package com.zhm.demo.utils;

import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

import java.net.URI;
import java.text.MessageFormat;

public class StringUtil {

    public static String messageFormat(String pattern, Object... arguments){
        return java.text.MessageFormat.format(pattern,arguments);
    }

    public static String uriComponents(String pattern, Object... arguments){
        UriComponents uriComponents = UriComponentsBuilder.fromUriString(pattern)
                .build()
                .expand(arguments)
                .encode();
        return uriComponents.toUri().toString();
    }


    public static void main(String[] args) {
        String s = messageFormat("http://USER-SERVICE/user?name={0}", 123);
        String s1 = uriComponents("http://USER-SERVICE/user?name={name}", 123);
        System.out.println(s);
    }
}
